package labox.innovation.gameserver.network.clientpackets;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import labox.innovation.config.Config;
import labox.innovation.gameserver.network.serverpackets.KeyPacket;

/**
 * 客户端上传的当前客户端的版本号
 * 
 * @version $Revision: 1.5.2.8.2.8 $ $Date: 2005/04/02 10:43:04 $
 */
public final class ProtocolVersion extends L2GameClientPacket {

	private static final String _C__00_PROTOCOLVERSION = "[C] 00 ProtocolVersion";

	private static final Logger _log = LoggerFactory.getLogger(ProtocolVersion.class.getName());

	private int _version;

	@Override
	protected void readImpl() {
		_version = readInt();
	}

	@Override
	protected void runImpl() {
		// this packet is never encrypted
		if (_version < Config.MIN_CLIENT_REVISION || _version > Config.MAX_CLIENT_REVISION) {
			if (_log.isDebugEnabled())
				_log.debug("Client Protocol Revision is incurrect: " + _version, Config.SERVER_ID, null);
			KeyPacket pk = new KeyPacket(getClient().enableCrypt(), 0);
			getClient().sendPacket(pk);
			getClient().setProtocolOk(false);
		} else {
			if (_log.isDebugEnabled())
				_log.debug("Client Protocol Revision is ok: " + _version, Config.SERVER_ID, null);

			KeyPacket pk = new KeyPacket(getClient().enableCrypt(), 1);
			getClient().sendPacket(pk);
			getClient().setProtocolOk(true);
		}
	}

	/* (non-Javadoc)
	 * @see labox.innovation.gameserver.clientpackets.ClientBasePacket#getType()
	 */
	@Override
	public String getType() {
		return _C__00_PROTOCOLVERSION;
	}
}
